#ifndef YSMOOTHANIMATION_H
#define YSMOOTHANIMATION_H

#include "Animation.h"

namespace Y{

template < class C >
class SmoothAnimation: public Animation<C> {
	
	public:
	
		float falloff;
		float placemark;
	
	public:
	
		SmoothAnimation( Entity *parentis ):
			Animation<C>(parentis),
			falloff(1.3),
			placemark(-1.0)
		{
			Entity::configure(
				C( speed	,	0.01 )
			);
		}
	
		virtual void handleConfig( ConfigVector& cv ){
			for ( int i = 0; i < cv.size(); ++i ){
				CH ( "falloff", falloff, float )
			}
			
			Animation<C>::handleConfig(cv);
		}
		
		virtual bool tick (float f = 1.0){
			if ( placemark < 0.0 && Animation<C>::counter < Animation<C>::endCount / 2.0 ){
				if ( Animation<C>::speed < 1.0 ){
					Animation<C>::speed *= falloff;
				}
				else{
					placemark = Animation<C>::counter - f;
				}
			}
			if ( Animation<C>::counter > Animation<C>::endCount - placemark || 
					( placemark < 0.0 && Animation<C>::counter >= Animation<C>::endCount / 2.0 ) ){
				Animation<C>::speed /= falloff;
			}
			
			return Animation<C>::tick(f);
		}
};


}
#endif